<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <title>分类管理</title>
    <script type="text/javascript" src="http://localhost/wasai/hdphp/Static/uploadify/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="http://localhost/wasai/hdphp/Static/uploadify/jquery.uploadify.min.js"></script>
	<link href="http://localhost/wasai/hdphp/Static/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
    <link rel="stylesheet" type="text/css" href="http://localhost/wasai/hdphp/Static/hdjs/hdjs.css">
</head>
<body>
<div class="wrap">
    <div class="hd-title-header">添加分类</div>
    <form action="" method="post" class="form-inline hd-form">
        <table class="hd-table hd-table-list">
            <tr>
                <th class="w100">分类名称</th>
                <td  class="w100">
                    <input type="text" name="cname" class="w200"/> 
                </td>
                <td>分类名称长度 1 到 20 位</td>
            </tr>
            <tr>
                <th class="w100">所属分类</th>
                <td>
                    <select name="pid" class="w200">
                    	<option value="0">顶级分类</option>
                    	<?php foreach($category as $v): ?>
                    	<option value="<?php echo $v['cid'] ?>"><?php echo $v['_name'] ?></option>
                    	<?php endforeach ?>
                    </select>
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">分类排序</th>
                <td>
                    <input type="text" name="sort" class="w200" value="100"/>
                </td>
                <td>请填写1到65535的排序数字 </td>
            </tr>
            <tr style="display: none;" class="type">
                <th class="typeid">类型名称</th>
                <td>
                	<select name="typeid" class="w200" >
	                	<?php foreach($type as $v): ?>
	                    <option value="<?php echo $v['tid'] ?>"><?php echo $v['tname'] ?></option>
	                    <?php endforeach ?>
                	</select>
                </td>
                <td></td>
           </tr>
           <tr id="picup" style="display: none;">
           	<td></td>
           	<td>
           	<input id="categorypic" type="file" multiple="true" name="categorypic">
	            <span>类型: *.jpg,*.png 推荐宽高：527*321</span>
	            <script type="text/javascript">
	                $(function() {
	                    $('#categorypic').uploadify({
	                        'formData'     : {//POST数据
	                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                        },
	                        'fileTypeDesc' : '上传文件',//上传描述
	                        'fileTypeExts' : '*.jpg;*.png',
	                        'swf'      : 'http://localhost/wasai/hdphp/Static/uploadify/uploadify.swf',
	                        'uploader' : '<?php echo U("uploadpic");?>',
	                        'buttonText':'选择文件',
	                        'fileSizeLimit' : '2000KB',
	                        'uploadLimit' : 1,//上传文件数
	                        'width':65,
	                        'height':25,
	                        'successTimeout':10,//等待服务器响应时间
	                        'removeTimeout' : 0.2,//成功显示时间
	                        'onUploadSuccess' : function(file, data, response) {
	                            data=$.parseJSON(data);
	                            var imageUrl = data.image?data.url:'http://localhost/wasai/hdphp/Static/image/default.png';
	                            var li="<li path='"+data.path+"' url='"+data.url+"' style='float: left'><img src='"+imageUrl+"' style='width:100px;heigth:100px;'/><a href='javascript:;'  class='del-img hd-btn hd-btn-danger hd-btn-xm'>删除</a>";
	                            //把地址放到隐藏域，这样可以提交到服务器了
	                            li += '<input type="hidden" name="categorypic" value="'+data.path+'"/>';
	                            li += '</li>';
	                            $("#uploadList ul").prepend(li);
	                        }
	                    });
	                });
	            </script>
	            <td>
	            	<div id="uploadList">
	            	<ul >
	 
	                </ul>
	            	</div>
	            </td>
	        </td>
           </tr>
        </table>
        <div class="position-bottom">
            <input type="submit" class="hd-btn hd-btn-success" value="添加"/>
        </div>
    </form>
    <script type="text/javascript">
   		$(function(){
			$("select[name=typeid]").val("0");
		});
    	$("select[name=pid]").change(function(){
    		if($(this).val()==0){
    			$(".type").hide();
    			$("select[name=typeid]").val("0");
    		}else{
    			$(".type").show();
    		}
    		$.ajax({
    			type:"post",
    			url:"<?php echo U('picopen');?>",
    			data:{cid:$(this).val()},
    			success:function(f){
    				if(f=='1')
    					$("#picup").show();
    				else
    					$("#picup").hide();
    			}
    		});
    	});
    </script>
    <script type="text/javascript">
		//点击x删除图片
		$('.del-img').live('click',function(){
			var liObj = $(this).parents('li');
			//找到父级li里面的地址
			var path = liObj.attr('path');
			//发异步到服务器删除
			$.ajax({
				type:"post",
				url:"<?php echo U('delImg');?>",
				data:{path:path},
				success:function(data){
					//移除图片
					liObj.remove();
				}
			});
		})
	</script>
</div>
</body>
</html>